import matplotlib.pyplot as plt
import numpy as np

train = [
    [1, 0], [5, 16], [6, 20], [9, 20], [11, 20], [15, 1], [19, 1]
]


def point_to_line(data):
    fig = plt.figure()
    x, y = [point[0] for point in data], [point[1] for point in data]
    plt.scatter(x, y)
    for i in range(len(x)):
        pos = '({a}, {b})'.format(a=x[i], b=y[i])
        plt.annotate(pos, xy=(x[i], y[i]), xytext=(x[i] + 0.2, y[i] + 0.1))

    plt.show()


def get_line_func(p1x, p1y, p2x, p2y):
    sign = 1
    a = p2y - p1y
    if a < 0:
        sign = -1
        a = sign * a
    b = sign * (p1x - p2x)
    c = sign * (p1y * p2x - p1x * p2y)
    return [a, b, c]


if __name__ == '__main__':
    point_to_line(train)
    last = train[0]
    for point in train[1:]:
        a, b, c = get_line_func(last[0], last[1], point[0], point[1])
        print("{a}x + {b}y + {c} = 0".format(a=a, b=b, c=c))
        last = point
